using UnityEngine;
using UnityEngine.UI;

namespace CGF
{
    public partial class PanelContactMyService : UIComponentBase, IAwake<UILayer, bool>, IDestroy
    {
        public static void Open()
        {
            UIManagerComponent.instance.OpenUI<PanelContactMyService>(UILayer.Normal, RootComponent.instance, false);
        }

        public static void Close()
        {
            UIManagerComponent.instance.CloseUI<PanelContactMyService>();
        }

        public async void Awake(UILayer layer, bool isFloat)
        {
            await SpawnPrefab("Prefabs/GameUI/PanelContactMyService", layer, isFloat);
            BindProperties(transform);

            BtnBack.SetClick(Close);

            BtnWhatsApp.text.text = Config.Get.WhatsAppNum;
            BtnTelegram.text.text = Config.Get.TelegramNum;
            BtnWhatsApp.SetClick(() =>
            {
                Application.OpenURL(Config.Get.WhatsAppNum);
            });
            BtnTelegram.SetClick(() =>
            {
                Application.OpenURL(Config.Get.TelegramNum);
            });

            InitData();
            EventManager.Add<Event_UserInfoUpdate>(OnUserInfoUpdate);
        }
        private void OnUserInfoUpdate(Event_UserInfoUpdate e)
        {
            InitData();
        }

        private void InitData()
        {
            Nickname.text = UserInfo.Info["name"].ToString();
            ID.text = $"ID: {UserInfo.Info["id"]}";
        }

        public override void OnDestroy()
        {
            base.OnDestroy();
            EventManager.Remove<Event_UserInfoUpdate>(OnUserInfoUpdate);
        }

    }
}
